<?php

// SELECT * FROM pre_person WHERE 1 ORDER BY LIMIT

//对象链
class DB2{
    public $sql = "";
    public $table = '';
    public $fields = '';
    public $where = '';
    public $order = '';
    public $limit = '';

    public function table($name)
    {
        $this->table = $name;
        return $this;
    }

    public function fields($name)
    {
        $this->fields = $name;
        return $this;
    }

    public function where($name)
    {
        $this->where = $name;
        return $this;
    }

    public function order($name)
    {
        $this->order = $name;
        return $this;
    }

    public function limit($name)
    {
        $this->limit = $name;
        return $this;
    }

    public function select()
    {
        $this->sql = "SELECT {$this->fields} FROM {$this->table} WHERE {$this->where} ORDER BY {$this->order} LIMIT {$this->limit}";

        return $this->sql;
    }


}

$db = new DB2();

//有很多框架调用数据库查询方法是比较灵活的
// $db->table('person') return $db;

$list = $db->table('person')
    ->fields('*')
    ->where("id = 1")
    ->order("id desc")
    ->limit(2)
    ->select();

var_dump($list);



?>